package com.mk.admin.service.impl;

import com.mk.admin.mapper.MessageMapper;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.entity.MessageEntity;
import com.mk.admin.model.vo.MessageVo;
import com.mk.admin.service.MessageService;
import com.mk.admin.util.DateTool;
import com.mk.admin.util.JSONCopy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageMapper messageMapper;

    @Override
    public ResultDto select(MessageVo messageVo) {
        MessageEntity entity = JSONCopy.copy(messageVo, MessageEntity.class);
        return ResultDto.data(messageMapper.count(entity), messageMapper.select(entity));
    }

    @Override
    public ResultDto add(MessageVo messageVo) {
        messageVo.setCreateTime(DateTool.format());
        return ResultDto.data(messageMapper.insert(JSONCopy.copy(messageVo, MessageEntity.class)));
    }

    @Override
    public ResultDto update(MessageVo messageVo) {
        return ResultDto.data(messageMapper.updateById(JSONCopy.copy(messageVo, MessageEntity.class)));
    }

    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(messageMapper.deleteById(id));
    }


    @Override
    public ResultDto status(int id) {
        return ResultDto.data(messageMapper.status(id));
    }
}
